import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * 描述:
 *
 * @author yanzhengwu
 * @create 2020-12-26 15:33
 */
public class JsoupTest3 {
    private String url;

    // 构造方法
    public JsoupTest3(String url) {
        this.url = url;
    }
    public JsoupTest3() {

    }

    public static void main(String[] args) {
        String url;
        /*if (args.length == 1) {
            url = args[0];
        } else {
            System.out.println(" usage: java SoupTest http:// ");
            return;
        }*/
        JsoupTest3 app = new JsoupTest3();
        app.run();
    }

    private static int table1(Document doc) {
        Elements trs = doc.select("table").select("tr");
        int i;
        for (i = 0; i < trs.size(); i++) {
            Elements tds = trs.get(i).select("td");
            for (int j = 0; j < tds.size(); j++) {
                String txt = tds.get(j).text();
                System.out.print(txt + " ");
            }
            System.out.println("");
        }
        return i;
    }

    // 运行过程
    public void run() {
        Document doc;
        int rows;
        try {
//            doc = Jsoup.connect(url).get();
            String htmlStr = "<table id=kbtable >"
                    + "<tr> "
                    + "<td width=123>"
                    + "<div id=12>这里是要获取的数据1</div>"
                    + "<div id=13>这里是要获取的数据2</div>"
                    + "</td>"
                    + "<td width=123>"
                    + "<div id=12>这里是要获取的数据3</div>"
                    + "<div id=13>这里是要获取的数据4</div>"
                    + "</td>	"
                    + "</tr>"
                    + "</table>";
            doc = Jsoup.parse(htmlStr);
            // Page: 1
            rows = table1(doc);
            System.out.println(" rows: " + rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
